<template>
  <div id="login">
    <ul>
      <form @submit.prevent="submit">
        <label for="name">YourName</label>
        <input id="name" type="text" name="name" v-model="inputtext.name">
        <label for="pwd">PassWord</label>
        <input id="pwd" type="password" name="password" v-model="inputtext.password">
        <input type="submit" value="登录">
      </form>
    </ul>
  </div>
</template>

<script>

export default {
  name: 'login',
  data () {
    return {
      inputtext: {},
      submitting: 0
    }
  },
  methods: {
    submit: function () {
      console.log(this.inputtext)
      if (this.submitting === 1) {
        return false
      }
      this.submitting = 1
      var that = this
      // this.$http.post(process.env.REST_URL + 'user/login', {name: this.inputtext.name, password: this.inputtext.password}, {credentials: true}).then((res) => {
      this.$http.post(process.env.REST_URL + 'user/login', {name: this.inputtext.name, password: this.inputtext.password}).then((res) => {
        this.submitting = 0
        if (res.data.status === 0) {
          console.log('SUCCESS')
          that.$emit('userSignIn', that.inputtext.name)
          this.$router.push('/HomeList')
        } else {
          alert(res.data.msg)
          console.log(res.data.msg)
        }
      }, function (response) {
        this.submitting = 0
        alert('login error')
        console.log('error')
      })
    }
  }

}

</script>

<style scoped>
  #paper {
    font-family: 'Avenir', Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-align: center;
    color: #2c3e50;
    margin-top: 60px;
  }
  h5{
    color: #999;
  }
</style>
